package com.ai.enviro.module.system.controller;


import com.ai.enviro.common.BaseController;
import com.ai.enviro.common.BaseResponse;
import com.ai.enviro.module.system.dao.dataobject.IotEnvDO;
import com.ai.enviro.module.system.service.IotEnvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2024-07-02
 */
@RestController
public class IotEnvController extends BaseController {

    @Autowired
    private IotEnvService iotEnvService;

    @PostMapping("/iot/upload")
    @ResponseBody
    public BaseResponse<String> iotUpload(@RequestBody byte[] bytes) {
        iotEnvService.saveIotEnv(bytes);
        return successResponse("");
    }

    @GetMapping("/iot/get")
    @ResponseBody
    public BaseResponse<IotEnvDO> iotGet() {
        byte[] testBytes = new byte[]{0x0a, 0x03, 0x04, 0x03, (byte)0x82, 0x01, 0x09, 0x21, 0x09};
        iotEnvService.saveIotEnv(testBytes);

        IotEnvDO iotEnv = iotEnvService.getIotEnv();
        return successResponse(iotEnv);
    }


}
